import { http } from '../../utils/request'

export const CHANNEL_SET_LIST = 'channel/setList'
export const CHANNEL_SET_ACTIVE = 'channel/setActive'

// 异步 action，内部返回函数
export const getChannel = () => {
  return async (dispatch) => {
    // 发送请求获取频道列表
    const res = await http.get('/v1_0/channels')
    console.log(res.data.channels)
    // 调用 dispatch 实现更新成后端返回的列表
    dispatch({ type: CHANNEL_SET_LIST, payload: res.data.channels })
  }
}

// 普通 action，返回普通对象
export const setActive = (index) => {
  return { type: CHANNEL_SET_ACTIVE, payload: index }
}
